package org.qf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.qf.dao.SmbmsUserDao;
import org.qf.entity.SmbmsUser;
import org.qf.service.SmbmsUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service //代表业务层
public class SmbmsUserServicelmpl implements SmbmsUserService {

    //调用dao
    @Autowired
    private SmbmsUserDao smbmsUserDao;

    //登录
    @Override
    public SmbmsUser login(String name,String password){
        SmbmsUser smbmsUser = smbmsUserDao.showUserByName(name);
        if(smbmsUser == null){
            //代表用户名为空
            return null;
        }else {
            if (smbmsUser.getUserPassword().equals(password)) {
                return smbmsUser;
            } else {
                return null;
            }
        }
    }

    //查询
    @Override
    public PageInfo<SmbmsUser> showList(int pageNum,SmbmsUser smbmsUser) {
        //设置
        PageHelper.startPage(pageNum,5);
        List<SmbmsUser> list = smbmsUserDao.showList(smbmsUser);
        PageInfo<SmbmsUser> pageInfo=new PageInfo<SmbmsUser>(list);
        if(pageInfo.getList().size()>0){
            return pageInfo;
        }else {
            return null;
        }
    }

    //增加用户
    @Override
    public  int addSmbmsUser(SmbmsUser smbmsUser){
        int i = smbmsUserDao.addSmbmsUser(smbmsUser);
        if(i>0){
            return i;
        }else {
            return 0;
        }
    }

    //查看功能
    @Override
    public SmbmsUser showUserById(int id){
        SmbmsUser smbmsUser = smbmsUserDao.showUserById(id);
        if(smbmsUser != null){
            return smbmsUser;
        }else {
            return null;
        }
    }

    //修改功能
    @Override
    public int updateUser(SmbmsUser smbmsUser){
        int i = smbmsUserDao.updateUser(smbmsUser);
        if(i > 0){
            return i;
        }else {
            return 0;
        }
    }


    //删除
    @Override
    public int deleteUser(int id) {
        int i = smbmsUserDao.deleteUser(id);
        if(i > 0){
            return i;
        }else {
            return 0;
        }
    }



}
